package com.lemon.smartsafetynew.ui.fragment.monitor;

import android.os.Bundle;

import com.lemon.smartsafety.app.RefreshType;
import com.lemon.smartsafety.listener.RecyclerTClickListener;
import com.lemon.smartsafetynew.ui.fragment.base.BasePullToRefreshFragment;
import com.lemon.smartsafety.utils.app.UIHelper;
import com.lemon.smartsafetynew.entity.monitor.MonitorItemVo;
import com.lemon.smartsafetynew.net.services.MonitorServices;
import com.lemon.smartsafetynew.ui.activity.monitor.MonitorDetailActivity;
import com.lemon.smartsafetynew.ui.adapter.monitor.MonitorItemAdapter;
import com.lemon.smartsafetynew.util.constants.KeyConstants;
import com.lemon.smartsafetynew.util.user.AccountUtil;
import com.lemon.smartsafetynew.util.user.UserTypeUtil;

import java.util.List;

import kale.adapter.LemonRcvAdapter;

/**
 * Created by Andrew on 2017/8/7.
 */

public class MonitorListFragment extends BasePullToRefreshFragment<MonitorItemVo, List<MonitorItemVo>>
        implements RecyclerTClickListener<MonitorItemVo> {

    @Override
    public void onPullRefresh() {
        MonitorServices.init().getMonitorPointList(RefreshType.REFRESH);
    }

    @Override
    public void onLoadMore() {
        MonitorServices.init().getMonitorPointList(RefreshType.LOAD_MORE);
    }

    @Override
    public boolean goRefreshOnCreate() {
        return true;
    }

    @Override
    public LemonRcvAdapter<MonitorItemVo> getLemonAdapter() {
        return new MonitorItemAdapter(mDataList, this);
    }

    @Override
    public String getHttpTag() {
        if (UserTypeUtil.isGovType(AccountUtil.getUserType())) { //政府人员使用模块
            return KeyConstants.URL_GET_MONITOR_DETAIL_LIST;
        } else {
            mPullToRefreshRecyclerView.onRefreshComplete();
            httpRefreshError("暂无更多数据：)");
            return "";
        }
    }

    public static MonitorListFragment newInstance() {

        Bundle args = new Bundle();

        MonitorListFragment fragment = new MonitorListFragment();
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    protected void initViews() {
        super.initViews();
    }

    @Override
    public void onItemClick(MonitorItemVo data, int position) {
        Bundle bundle = new Bundle();
        bundle.putSerializable(KeyConstants.KEY_MONITOR_ITEM_VO, data);
        UIHelper.showActivity(getmContext(), bundle, MonitorDetailActivity.class);
    }
}
